package com.Dao.impl;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class JDBCUtilis {
    private static String aClass = null;
    private static String username = null;
    private static String password = null;
    private static String driverManager = null;

    static {

        try {
            Properties properties = new Properties();
            InputStream is = JDBCUtilis.class.getClassLoader().getResourceAsStream("sql.properties");
            properties.load(is);
            aClass = properties.getProperty("Class");
            username = properties.getProperty("username");
            password = properties.getProperty("password");
            driverManager = properties.getProperty("DriverManager");
            Class.forName("aClass");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(driverManager,username,password);
    }
    public static void Close(ResultSet re, Statement st , Connection co){
        if (re!=null){
            try {
                re.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (st!=null){
            try {
                st.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (st!=null){
            try {
                st.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (co!=null){
            try {
                co.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
    }
}
